package com.ftg.learn.chapter04;

import com.sun.org.apache.bcel.internal.generic.LSHL;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

/**
 * 学习字符串以及面向对向基础
 *
 * @author 布衣
 */
public class LearnString {

    public static void main(String[] args) {
        String str = "abc";
        String str1 = new String("abc");
        String str2 = new String("abc");

        //引用类型  当中  ==判断是否为同一个内存地址
        System.out.println(str == str1);
        System.out.println(str1 == str2);

        String str3 = "ab" + "c";

        System.out.println(str == str3);

        //变量参与运算了  jdk1.5 以后  优化了一下  变量参与运算
        String str4 = "ab";
//        String str5 = str4 + "c";
        String str5 = new StringBuilder(str4).append("c").toString();


        System.out.println(str == str5);

        String str6 = str4.concat("c");
        System.out.println(str == str6);

        int[] arr = {1,2,3};
        int[] arr01 = Arrays.copyOf(arr,6);

        System.out.println(Arrays.toString(arr01));


        String str7 = str1.intern();

        System.out.println(str1 == str7);



        //一段不可变更字符序列
        String str8 = "tttt";

        String str9 = "abc";
//        hashCode  hash算法
        System.out.println("a".hashCode());
        System.out.println("ab".hashCode());

        System.out.println(new String(new char[]{'a', 'b', 'c', 'd'},2,2));
        System.out.println("abc".codePointAt(0));

        System.out.println("中国abc".length());

        try {

            System.out.println("中国abc".getBytes("GBK").length);
            System.out.println("中国abc".getBytes("gb2312").length);
            System.out.println("中国.。".getBytes("utf-8").length);


        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

        System.out.println("abcde".indexOf("dc"));
//    [2,6)
        System.out.println("abcdef".substring(2,6));

        String s = "13526619037";
//        System.out.println(s.replace(s.substring(3, 7), "****"));
//        System.out.println(s.replace("2661", "****"));
//        System.out.println(s.substring(0, 3) + "****" + s.substring(7));
//
//        System.out.println("中国".getBytes(StandardCharsets.UTF_8));

        String reg = "^(153|147|139)\\d*";
        System.out.println(s.matches(reg));
        String usernameReg ="^\\w{6,8}$";


        System.out.println("abc123abc123abc".replaceAll("abc", "888"));

        "1999-9-9".split("\\d+");

        //把我们那个注册功能，添加上正则表达式验证

        //Arrays 源码底码  自行去查看一下

        //会有一些基本的字符串 (快速写完)

        // kmp (读一下，理解) （....）

        //去刨一下力扣 字符串(中等2)x

        System.out.println(String.join("-", "aaa", "bbb", "ccc"));

    }

}
